package com.mhg.generic;

import java.util.ArrayList;
import java.util.Iterator;



public class Demo_03 {

	public static void main(String[] args) {
		ArrayList<People> al = new ArrayList<>();
		al.add(new People("张三"));
		al.add(new People("张三2"));
		al.add(new People("张三3"));
		printColl(al);
		
		ArrayList<Student> al2 = new ArrayList<>();
		al2.add(new Student("李四"));
		al2.add(new Student("李四2"));
		printColl(al2);
		
//		ArrayList<Person> al3 = new ArrayList();
//		al3.add(new Person("哈哈", 11));
//		printColl(al3);
	}
	public static void printColl(ArrayList<? extends People> al){
		Iterator<? extends People> it = al.iterator();
		while(it.hasNext()){
			People p = it.next();
			System.out.println(p.getName());
		}
	}

}
class People{
	private String name;
	People(String name){
		this.name = name;
	}
	public String getName(){
		return name;
	}
}
class Student extends People{
	Student(String name){
		super(name);
	}
}